﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using clsEmployeeList.Forms;
using libAddressBook.FORMS;
using libMasterSetup.Forms.Billing;
using libMasterSetup.Forms.SalesTermsAndTrade;
using libInventory.FORMS;
using libQoutation.Forms;

namespace libLogin.Forms
{
    public partial class mdiEsbSsytems : Form
    {
        private frmUserProfile frmProf = null;
        private int childFormNumber = 0;
        frmLogin Hold;

        struct CheckOpenForms
        { 
        
            
        };

        public mdiEsbSsytems(ref frmLogin Login)
        {
            InitializeComponent();
            Hold = Login;
        }



        private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
            childForm.MdiParent = this;
            childForm.Text = "Window " + childFormNumber++;
            childForm.Show();
        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
         //   toolStrip.Visible = toolBarToolStripMenuItem.Checked;
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
          //  statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void accessToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmUserProfile x = new frmUserProfile();
            x.MdiParent = this;
            x.Show();
        }

        private void mdiEsbSsytems_FormClosed(object sender, FormClosedEventArgs e)
        {
          //  Hold.Show();
            Application.Exit(); 
        }

        private void cbddAdministrator_Click(object sender, EventArgs e)
        {
            //if (rmAdminUserAccess.Selected == true)
            //{
            //    frmUserProfile x = new frmUserProfile();
            //    x.MdiParent = this;
            //    x.Show();
            //}
        }

        private void radCommandBar1_RootElement_Click(object sender, EventArgs e)
        {
            if (rmAdminUserAccess.Selected == true)
            {
                frmUserProfile x = new frmUserProfile();
                x.MdiParent = this;
                x.FormBorderStyle = FormBorderStyle.None;
                x.ControlBox = false;
                x.MinimizeBox = false;
                x.MaximizeBox = false;
                x.Show();
                x.Dock = DockStyle.Fill;
            
             
            }
            else if (miAddressbook.Selected == true)
            { 
            }
        }

        private void mdiEsbSsytems_Load(object sender, EventArgs e)
        {

            try
            {
                this.rmAdminUserAccess.Click += new EventHandler(rmAdminUserAccess_Click);
                this.miAddressbook.Click += new EventHandler(miAddressbook_Click);
                this.miTradeAndSalesSetup.Click += new EventHandler(miTradeAndSalesSetup_Click);
                this.miFixOptionalCharges.Click += new EventHandler(miFixOptionalCharges_Click);
                this.miSalesTermsSetup.Click += new EventHandler(miSalesTermsSetup_Click);
                this.miGRNMain.Click += new EventHandler(miGRNMain_Click);
         // this.miRequisitionBooking + = new EventHandler ();
                this.miFreight.Click += new EventHandler(miFreight_Click);
                this.miQuotationlcl.Click += new EventHandler(miQuotationlcl_Click);


                    this.IsMdiContainer = true;
                    this.ShowIcon = true;
                    this.radDock1.AutoDetectMdiChildren = true;
                    radDock1.DockWindowAdded += new Telerik.WinControls.UI.Docking.DockWindowEventHandler(radDock1_DockWindowAdded);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " miQuotationlcl_Click");
            }
        }
        private void miQuotationlcl_Click(object sender, EventArgs e)
        {
            try
            {

                frmLCLQoutation x = new frmLCLQoutation();
                x.MdiParent = this;
                x.ControlBox = false;
                x.MinimizeBox = false;
                x.MaximizeBox = false;
                x.Show();
                x.Dock = DockStyle.Fill;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " miQuotationlcl_Click");
            }
        }

        private void miFreight_Click(object sender, EventArgs e)
        {
            try
            {
                frmFreight x = new frmFreight();
                x.MdiParent = this;
                x.ControlBox = false;
                x.MinimizeBox = false;
                x.MaximizeBox = false;
                x.Show();
                x.Dock = DockStyle.Fill;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " miFreight_Click");
            }
        }

        private void miGRNMain_Click(object sender, EventArgs e)
        {
            try
            {
                frmGRN x = new frmGRN();
                x.MdiParent = this;
                x.ControlBox = false;
                x.MinimizeBox = false;
                x.MaximizeBox = false;
                x.Show();
                x.Dock = DockStyle.Fill;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " miGRNMain_Click");
            }
        }

        private void miSalesTermsSetup_Click(object sender, EventArgs e)
        {
            try
            {
                frmSalesAndTrade x = new frmSalesAndTrade();
                x.MdiParent = this;
                x.ControlBox = false;
                x.MinimizeBox = false;
                x.MaximizeBox = false;
                x.Show();
                x.Dock = DockStyle.Fill;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " miSalesTermsSetup_Click");
            }

        }

        private void miFixOptionalCharges_Click(object sender, EventArgs e)
        {
            try
            {
                frmChargesSetup x = new frmChargesSetup();
                x.ControlBox = false;
                x.MinimizeBox = false;
                x.MaximizeBox = false;
                x.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " miFixOptionalCharges_Click");
            }
        }
       

        private void miTradeAndSalesSetup_Click(object sender, EventArgs e)
        {
            try
            {
                frmFixOptionalCosting x = new frmFixOptionalCosting();
                x.MdiParent = this;
                x.FormBorderStyle = FormBorderStyle.None;
                x.ControlBox = false;
                x.MinimizeBox = false;
                x.MaximizeBox = false;
                x.Show();
                x.Dock = DockStyle.Fill;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " miFixOptionalCharges_Click");
            }
        }

        void miAddressbook_Click(object sender, EventArgs e)
        {
            try
            {
                frmAddressBook x = new frmAddressBook();
                x.MdiParent = this;
                x.FormBorderStyle = FormBorderStyle.None;
                x.ControlBox = false;
                x.MinimizeBox = false;
                x.MaximizeBox = false;
                x.Show();
                x.Dock = DockStyle.Fill;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " miFixOptionalCharges_Click");
            }
        }

        private bool set_OpenForm(string strApplication)
        {
            bool IsOpen = false;
            try
            {
                foreach (Form f in this.MdiChildren )
                {
                    if (f.Text.Contains(strApplication) == true)
                    {
                        IsOpen = true;
                        f.Focus();
                        break;
                    }
                }
            }
            catch (Exception ex)
            { 
            }
            return IsOpen;
        }

        private void rmAdminUserAccess_Click(object sender, EventArgs e)
        {
            try
            {
                if (set_OpenForm("User") == false)
                {
                    frmProf = new frmUserProfile();

                    frmProf.MdiParent = this;
                    frmProf.FormBorderStyle = FormBorderStyle.None;
                    frmProf.ControlBox = false;
                    frmProf.MinimizeBox = false;
                    frmProf.MaximizeBox = false;
                    frmProf.Show();
                    frmProf.Dock = DockStyle.Fill;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " miFixOptionalCharges_Click");
            }
        }

        private void radDock1_DockWindowAdded(object sender, Telerik.WinControls.UI.Docking.DockWindowEventArgs e)
        {
            radDock1.ActiveWindow = e.DockWindow;
        }

        private void cbddMasterSetup_Click(object sender, EventArgs e)
        {

        }

        private void radDock1_SelectedTabChanged(object sender, Telerik.WinControls.UI.Docking.SelectedTabChangedEventArgs e)
        {
           // MessageBox.Show(e.NewWindow.Text);
        }

       
    }
}
